package com.dc.project.controller;

import com.dc.common.core.LoginBody;
import com.dc.common.validated.UserFormGroup;
import com.dc.common.vo.ResultVo;
import com.dc.project.service.AuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhuangcy
 * @date 2021/6/1
 * @description 用户登录验证控制类
 */
@Api(tags = "用户登录验证控制类")
@RestController
public class AuthController {

    @Autowired
    private AuthService authService;

    /**
     * 表单登录
     *
     * @param loginBody
     * @return
     */
    @ApiOperation("登录")
    @PostMapping("/login")
    public ResultVo login(@RequestBody @Validated(UserFormGroup.class) LoginBody loginBody) {
        return authService.login(loginBody);
    }

    /**
     * 登出
     *
     * @return
     */
    @ApiOperation("登出")
    @GetMapping("/logout")
    public ResultVo logout() {
        return authService.logout();
    }

    /**
     * 获取用户信息
     *
     * @return
     */
    @ApiOperation("获取用户信息")
    @GetMapping("/userInfo")
    public ResultVo getUserInfo() {
        return authService.getUserInfo();
    }


}
